package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

//日报对象
@Data
public class News extends BaseDomain {
    public static final Integer ISRELEASE_TEMP = 0; //草稿
    public static final Integer ISRELEASE_RELEASE = 1; //发布

    public static final Integer STATE_TEMP = 0; //未收藏
    public static final Integer STATE_RELEASE = 1; //已经收藏

    private String coverUrl;    //封面

    private String title;       //标题

    private String abstracts;   //摘要

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date createTime;    //创建时间

    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date releaseTime;   //发布时间

    private Integer isRelease = ISRELEASE_TEMP;  //是否发布

    private Integer state = STATE_TEMP;      //状态：是否收藏

    //private User author;        //作者
    //private NewsType type;       //日报文章的类型  1.美图美文 2.旅游法务 3.地区新闻

    private Long typeId;        //文章类型id
    private String typeName;    //文章的类型

    //private Integer newsNum;  //此日报收藏数量

    private NewsContent newsContent;    //日报内容

    public String getIsReleaseName(){
        String msg = "草稿";
        if (isRelease == ISRELEASE_RELEASE){
            msg = "发布";
        }
        return msg;
    }

    public String getStateName(){
        String msg = "未收藏";
        if (state == STATE_RELEASE){
            msg = "已经收藏";
        }
        return msg;
    }

    public String getJson(){
        Map<String, Object> map = new HashMap<>();
        map.put("id",id);
        map.put("coverUrl",coverUrl);
        map.put("title",title);
        map.put("abstracts",abstracts);
        map.put("typeId",typeId);
        map.put("typeName",typeName);
        if (releaseTime != null){
            map.put("releaseTime", DateUtil.formatDate(releaseTime));
        }
        return JSONUtil.toJSONString(map);
    }

}